#include "MemoryManager.h"

NS_CC_CORE_BEGIN





static MemoryManager*		s_sharedMemoryManager = NULL;

MemoryManager* MemoryManager::sharedMemoryManager( )
{
	if( s_sharedMemoryManager == NULL )
	{
		s_sharedMemoryManager = new MemoryManager( );
	}

	return s_sharedMemoryManager;
}

MemoryManager::MemoryManager( )
{
	m_pListMemoryObj = LStaticArray<MemoryManagerDelegate>::create();
}


MemoryManager::~MemoryManager( )
{
	if( m_pListMemoryObj )
	{
		CC_SAFE_DELETE(m_pListMemoryObj);
	}
}


void MemoryManager::purge( )
{
	CC_SAFE_DELETE( s_sharedMemoryManager );
	NotificationCenter::purge( );
}

void MemoryManager::add( MemoryManagerDelegate* pObj )
{
	m_pListMemoryObj->addObject(pObj);
}




//---------------------------Memory manager delegate class implement------------------------------//
MemoryManagerDelegate::MemoryManagerDelegate( )
{
	MemoryManager::sharedMemoryManager()->add( this );
}


MemoryManagerDelegate::~MemoryManagerDelegate( )
{

}
//---------------------------end Memory manager delegate class implement-------------------------//

NS_CC_CORE_END